<template>
    <div>
        <van-nav-bar title="收货地址" left-text="返回" left-arrow @click-left="onClickLeft" />
        <van-address-list v-model="chosenAddressId" :list="list.data" @add="onAdd" @edit="onEdit" />

    </div>
</template>

<script setup lang="ts">
import { useStore } from 'vuex';
import { selectuseraddress } from '@/api/index'
import { showToast } from 'vant';
import { reactive, ref } from 'vue';
import { useRouter } from 'vue-router';
const chosenAddressId = ref('1');
let router = useRouter()
let store = useStore()

let list = reactive({
    data: [] as any
})
selectuseraddress(store.state.userData[0].id).then((result: any) => {
    list.data = result.data.data
}).catch((err: any) => {
    console.log(err);
});


const onAdd = () => {
    router.push({
        path: '/bianjiaddress'
    })
};
const onEdit = (item: any) => {
    store.commit('updateuserraddress', item)
    router.push({
        path: '/updateaddress'
    })
}


const onClickLeft = () => history.back();
</script>

<style lang="less" >

.van-nav-bar .van-icon{
    color: #333333;
}
.van-nav-bar__text{
    color: #333333;
}</style>